package me.miencraft.plugin.worldinfo;

import lombok.Getter;
import org.bukkit.World;

/**
 * @author langle__
 * @version 1.0
 */
@Getter
public enum MoonPhase {

    FULL_MOON(0), // 满月
    WANING_GIBBOUS(1), // 亏凸月
    LAST_QUARTER(2), // 下弦月
    CRESCENT(3), // 残月
    NEW_MOON(4), // 新月
    CRESCENT_WAXING(5), // 蛾眉月
    FIRST_QUARTER(6), // 上弦月
    WAXING_GIBBOUS(7); // 盈凸月

    private final int index;

    MoonPhase(int index) {
        this.index = index;
    }

    // 根据索引获取对应的枚举值
    public static MoonPhase fromIndex(int index) {
        if (values().length <= index) {
            throw new IllegalArgumentException("Invalid moon phase index: " + index);
        }
        return values()[index];
    }

    public static MoonPhase fromWorldTime(World world) {
        return fromIndex((int) (world.getFullTime() / 24000L % 8L + 8L) % 8);
    }

}

